package pl.edu.wsinf.lukaszwalczak.emailclient.controller;

import javax.inject.Inject;
import org.springframework.stereotype.Component;
import pl.edu.wsinf.lukaszwalczak.emailclient.pojo.Folder;
import pl.edu.wsinf.lukaszwalczak.emailclient.pojo.Mail;
import pl.edu.wsinf.lukaszwalczak.emailclient.repository.MailRepository;
import pl.edu.wsinf.lukaszwalczak.emailclient.service.AccountService;
import pl.edu.wsinf.lukaszwalczak.emailclient.view.MailListView;

@Component
public class MailListController {

    @Inject
    private MailRepository mailRepository;
    @Inject
    private AccountService accountService;
    @Inject
    private MailListView view;

    public void removeMail(Mail mail) {
        mailRepository.delete(mail);
    }

    public void setRead(Mail mail, boolean read) {
        mail.setRead(read);
        mailRepository.save(mail);
    }

    public void moveToTrash(Mail mail) {
        Folder trash = accountService.getTrashFolder(mail.getAccount());
        moveToFolder(mail, trash.getName());
    }

    public void moveToFolder(Mail mail, String folder) {
        mail.setFolder(folder);
        mailRepository.save(mail);
    }
}
